Skip to content

fix(java,kotlin): read the credential key from Jackson's contract so a naming strategy cannot leak it - #601

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-java-kotlin-credential-fix
Nov 18, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-java-kotlin-credential-fix

Conversation

@dmealing

Copy link
Copy Markdown
Member

What Changed

  • The generated Java and Kotlin Spring controllers' redact helper no longer removes the credential key by the Java field name. It reads each credential's wire key from the host ObjectMapper's own serialization contract (SerializationConfig.introspect(...).findProperties(), matched on the property's internal name, cached per row class), so a naming strategy (SNAKE_CASE/KEBAB_CASE), mixin or @JsonProperty rename can no longer leave the credential in the response; a second pass also removes any key spelling a credential ignoring case, _ and -. Every redaction site (get, list, create/update echo, M:N traversal, TPH, projection, report) routes through the shared helper.
  • Stripping now fails closed: when the contract cannot be read (the row's serializer is not a bean serializer, or the class declares the credential but the contract has no property for it and does not ignore it), the request is refused with an exception naming the type and credential property instead of being sent unstripped — matching the C# fix.
  • The Java and Kotlin secret-fields generated-controller conformance lanes gained a none/snake/kebab naming-strategy parameter plus mixin-rename and custom-serializer fail-closed tests over embedded Tomcat (seeding made naming-independent); the harnesses accept a naming strategy and mapper customizer. CHANGELOG.md documents the leak for released 8.2.0–8.2.3, and the secret-fields corpus README states redaction is naming-strategy independent.
Validation

Risk Assessment

✅ Low: Well-bounded security fix whose generated helpers fail closed, verified by behavior tests with independent seed-value oracles across both JVM ports; the fix-round code matches the recorded round-1 decision exactly and introduces no unrequired machinery.

Testing

Drove the credential-redaction fix end-to-end on both changed ports: each conformance test runs the real codegen-spring / codegen-kotlin generator on the secret-fields corpus, compiles the emitted controller with javac/Kotlin compiler, hosts it over embedded Tomcat, and exchanges real HTTP requests. Java lane 8/8 green, Kotlin lane 7/7 green. Naming-strategy cases (default, SNAKE_CASE, KEBAB_CASE) confirm pinHash is absent from entity list/get and the inheriting projection's routes while tokenHash is still returned under the strategy's own key (snake/kebab spelled), proving redaction keys off the mapper's contract, not the field name. Adversarial cases confirm the review-round fixes: a @JsonProperty mixin renaming the credential to "secret" still strips it, and a custom bean-less serializer makes the controller refuse the response with 500 ("cannot strip the credential ... the response is refused rather than sent unstripped") with no credential value in any body. Baseline broad regression came from the configured command scripts/ci-local.sh --affected --strict-toolchains, which passed at this target commit; I did not rerun it. No stray processes or temp dirs left behind.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Java generated Spring controller never returns the credential under default, SNAKE_CASE and KEBAB_CASE naming strategies (entity list/get plus credential-inheriting projection list/get; tokenHash stil… ✅ pass live Java surefire report: Tests run: 8, Failures: 0, Errors: 0 (parameterized naming={none,snake,kebab} cases), artifact java-secretfields-conformance.txt
Kotlin generated Spring controller never returns the credential under default, SNAKE_CASE and KEBAB_CASE naming strategies (entity list/get plus inheriting projection list/get; tokenHash still returne… ✅ pass live Kotlin surefire report: Tests run: 7, Failures: 0, Errors: 0 (parameterized naming={none,snake,kebab} cases), artifact kotlin-secretfields-conformance.txt
Adversarial fail-closed and rename evasion on both ports: a custom serializer forces a 500 refusal with no credential in the body, and a @JsonProperty mixin renaming the credential to a non-normalizin… ✅ pass live credentialRenamedByAMixinIsNeverReturned and customSerializerForTheRowRefusesTheResponse green on both ports; Tomcat SEVERE logs show the generated controller throwing "cannot strip the credential Acc…
Evidence: Java generated-controller secret-fields conformance (surefire)

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0 -- SecretFieldsGeneratedApiContractConformanceTest

-------------------------------------------------------------------------------
Test set: com.metaobjects.integration.api.SecretFieldsGeneratedApiContractConformanceTest
-------------------------------------------------------------------------------
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.206 s -- in com.metaobjects.integration.api.SecretFieldsGeneratedApiContractConformanceTest
Evidence: Kotlin generated-controller secret-fields conformance (surefire)

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0 -- SecretFieldsGeneratedApiContractConformanceTest

-------------------------------------------------------------------------------
Test set: com.metaobjects.integration.kotlin.api.secretfields.SecretFieldsGeneratedApiContractConformanceTest
-------------------------------------------------------------------------------
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 12.83 s -- in com.metaobjects.integration.kotlin.api.secretfields.SecretFieldsGeneratedApiContractConformanceTest
Evidence: Java fail-closed 500 under custom serializer (embedded Tomcat log)

IllegalStateException: cannot strip the credential AccountDto.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed: java.lang.IllegalStateException: cannot strip the credential AccountDto.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.] with root cause
Evidence: Kotlin fail-closed 500 under custom serializer (embedded Tomcat log)

IllegalStateException: cannot strip the credential Account.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed: java.lang.IllegalStateException: cannot strip the credential Account.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.] with root cause

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringSecretFieldsCodegenTest.java:90 - New codegen unit tests assert only that the emitted controller text contains implementation tokens (config.introspect(objectMapper.constructType(type)), p.getInternalName().equals(name), throw unstrippable(, key.replace("_", "")...). Matching text is a proxy for behavior: it passes if the code is dead or the fix is refactored, and it would still pass if the helper were wrong. Behavior is already proven by the none/snake/kebab integration lanes, so these add no independent evidence. Same pattern in the Kotlin twin: KotlinSecretFieldsTest.kt the credential key is read from the mapper's contract... (about line 55). Remove both, or replace with a compile-and-run test that covers what the lanes do not: fail-closed (a custom serializer or missing property must throw), @JsonProperty/mixin rename, and the second-line-of-defence key removal. The pre-existing contains(...) updates in KotlinSecretFieldsTest and KotlinReportCredentialTest only track the renamed emitted call and are the same existing style.

🔧 Fix applied.
1 warning still open:

  • ⚠️ server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringSecretFieldsCodegenTest.java:90 - New codegen unit tests assert only that the emitted controller text contains implementation tokens (config.introspect(objectMapper.constructType(type)), p.getInternalName().equals(name), throw unstrippable(, key.replace("_", "")...). Matching text is a proxy for behavior: it passes if the code is dead or the fix is refactored, and it would still pass if the helper were wrong. Behavior is already proven by the none/snake/kebab integration lanes, so these add no independent evidence. Same pattern in the Kotlin twin: KotlinSecretFieldsTest.kt the credential key is read from the mapper's contract... (about line 55). Remove both, or replace with a compile-and-run test that covers what the lanes do not: fail-closed (a custom serializer or missing property must throw), @JsonProperty/mixin rename, and the second-line-of-defence key removal. The pre-existing contains(...) updates in KotlinSecretFieldsTest and KotlinReportCredentialTest only track the renamed emitted call and are the same existing style.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Java generated Spring controller never returns the credential under default, SNAKE_CASE and KEBAB_CASE naming strategies (entity list/get plus credential-inheriting projection list/get; tokenHash stil… ✅ pass live Java surefire report: Tests run: 8, Failures: 0, Errors: 0 (parameterized naming={none,snake,kebab} cases), artifact java-secretfields-conformance.txt
Kotlin generated Spring controller never returns the credential under default, SNAKE_CASE and KEBAB_CASE naming strategies (entity list/get plus inheriting projection list/get; tokenHash still returne… ✅ pass live Kotlin surefire report: Tests run: 7, Failures: 0, Errors: 0 (parameterized naming={none,snake,kebab} cases), artifact kotlin-secretfields-conformance.txt
Adversarial fail-closed and rename evasion on both ports: a custom serializer forces a 500 refusal with no credential in the body, and a @JsonProperty mixin renaming the credential to a non-normalizin… ✅ pass live credentialRenamedByAMixinIsNeverReturned and customSerializerForTheRowRefusesTheResponse green on both ports; Tomcat SEVERE logs show the generated controller throwing "cannot strip the credential Acc…
  • scripts/ci-local.sh --affected --strict-toolchains
  • mvn -f server/java/integration-tests/pom.xml test -Dtest=SecretFieldsGeneratedApiContractConformanceTest (8 tests: corpus scenarios, projection inheritance, naming none/snake/kebab, mixin rename, custom-serializer fail-closed)
  • mvn -f server/java/integration-tests-kotlin/pom.xml test -Dtest=SecretFieldsGeneratedApiContractConformanceTest (7 tests: same matrix on the Kotlin generator)
  • Baseline broad regression: scripts/ci-local.sh --affected --strict-toolchains already passed at target commit c75e4166a
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…a naming strategy cannot leak it

The generated Spring controllers (codegen-spring, codegen-kotlin) hid a credential
(a view.password field) by serializing the row to a JSON tree and removing the key
spelled with the field name. Under a SNAKE_CASE or KEBAB_CASE Jackson naming strategy
the key is pin_hash / pin-hash, the removal found nothing, and the credential was sent
in every response. Released Java and Kotlin 8.2.0 to 8.2.3 are affected.

The shared redact helper now:
- reads each credential's wire key from the mapper's serialization contract
  (introspect().findProperties(), matched on the internal name), cached per row class,
  so a naming strategy, mixin or @JsonProperty is honoured;
- fails closed: a row whose serializer is not a bean serializer, or whose class declares
  the credential with no matching (and not ignored) property, is refused, not sent;
- also removes any key spelling the credential ignoring case, '_' and '-'.

Every response path (list, get, create/update echo, M:N, TPH, projection, report JSON)
already goes through the helper; the Kotlin M:N traversal now uses it too. The report
CSV/XML exports write a fixed column list without credentials and never touch Jackson.

The Java and Kotlin secret-fields generated-controller lanes gain a none/snake/kebab
naming parameter over list, get-by-id and an inheriting projection (the Kotlin harness
gains the projection); both leak under snake and kebab without the fix.
@dmealing
dmealing merged commit c724c95 into main Nov 18, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-java-kotlin-credential-fix branch November 18, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant